import {siteNavList} from '@/api/home'
import { ref } from 'vue'
import { getGoodsPart } from '@/api/home'

export default {
    namespaced: true,
    state () {
      return {
        // 网站导航分类集合
        siteNavList,
        // 当前商品栏目板块
        currentGoodsCol: ref([]),

        // 手机和企业购专区
        phoneGoodsPart: ref([]),

        // 电脑、笔记本、精品平板、台式机、显示器、电脑配件专区
        computerGoodsPart: ref([])
      }
    },
    // 修改分类函数
  mutations: {
    // 得到对应商品专区数据
    setCurrentGoodsPart(state, goodsData) {
      const { goodsPart, data } = goodsData
      state[goodsPart].value = data
    },
    // 传对应商品名，得到对应商品栏目板块
    showGoodsColPart (state, goodsColData) {
      const { currentName, data } = goodsColData
      state.currentGoodsCol.value = data.find(item => item[0].goodsName == currentName)
    }
  },
  // 点击某个商品专区模块请求
  actions: {
    async getCurrentGoodsPart({ commit }, args) {
      const data = await getGoodsPart(args.title)
      data.goodsPart = args.part
      commit('setCurrentGoodsPart', data )
    }
  }
}